// https://leetcode.cn/problems/valid-palindrome/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    bool isPalindrome(string s) {
        string p = "";
        int n = s.size();
        for (int i = 0; i < n; i++) {
            if (isalpha(s[i]) || (s[i] >= '0' && s[i] <= '9')) {
                p += tolower(s[i]);
            }
        }

        n = p.size();
        if (n <= 1) return true;

        for (int i = 0; i < n / 2; i++) {
            if (p[i] != p[n - i - 1]) return false;
        }
        return true;
    }
};